package com.tjetc.dao;

import com.tjetc.domain.Fan;
import com.tjetc.utils.Db;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class FanDao {
    public Fan log(String username, String password) throws SQLException {
        return Db.runner.query("select * from fan where username=? and password=?",new BeanHandler<>(Fan.class),username,password);
    }

    public Fan fandByFanId(int fanId) throws SQLException {
        return Db.runner.query("select * from fan where id=?" ,new BeanHandler<>(Fan.class),fanId);
    }

    public boolean del(int fanId) throws SQLException {
        int update = Db.runner.update(Db.getConnection(), "delete from fan where id=?", fanId);
        return update!=0;
    }

    public boolean fanUpdateUsername(String newUsername,int fanId) throws SQLException {
        int update = Db.runner.update(Db.getConnection(),"update fan set username=? where id=?",newUsername,fanId);
        return update!=0;
    }

    public boolean fanupdatePassowrd(String newdate, int fanId) throws SQLException {
        int update= Db.runner.update(Db.getConnection(),"update fan  set password=? where id=?",newdate,fanId);
        return update!=0;
    }

    public boolean fanupdateName(String newName, int fanId) throws SQLException {
        int update= Db.runner.update(Db.getConnection(),"update fan  set name=? where id=?",newName,fanId);
        return update!=0;
    }

    public boolean fanupdatePhone(String newPhone, int fanId) throws SQLException {
        int update= Db.runner.update(Db.getConnection(),"update fan  set phone=? where id=?",newPhone,fanId);
        return update!=0;
    }
}
